var t = getApp(), e = t.requirejs("core");

t.requirejs("foxui");

Page({
    data: {
        icons: t.requirejs("icons"),
        page: 1,
        loading: !1,
        loaded: !1,
        isedit: !1,
        isCheckAll: !1,
        checkObj: {},
        checkNum: 0,
        list: [],
        textcontent: '提示：未开启'
    },
    onLoad: function(e) {
      t.url(e), this.getList(), this.testingTap();
    },
    onReachBottom: function() {
        this.data.loaded || this.data.list.length == this.data.total || this.getList();
    },
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh();
    },
    getList: function() {
        var t = this;
        t.setData({
            loading: !0
        }), e.get("member/favorite/get_list", {
            page: t.data.page
        }, function(e) {
            var i = {
                loading: !1,
                loaded: !0,
                total: e.total,
                pagesize: e.pagesize,
                show: !0
            };
            e.list.length > 0 && (i.page = t.data.page + 1, i.list = t.data.list.concat(e.list), 
            e.list.length < e.pagesize && (i.loaded = !0)), t.setData(i);
        });
    },
    checkAllClick: function() {
        var t = !this.data.isCheckAll, e = this.data.checkObj, i = {
            isCheckAll: t,
            checkObj: e
        };
        for (var a in e) i.checkObj[a] = !!t;
        i.checkNum = t ? this.data.list.length : 0, this.setData(i);
    },
  // 检测是否开启  更新提示
  testingTap: function () {
    let that = this;
    wx.getSetting({
      withSubscriptions: true,
      success(res) {
        console.log(res)
        //返回authSetting
        // res.authSetting = {
        //   "scope.userInfo": true,
        //   "scope.userLocation": true
        // },
        if (res.errMsg == 'getSetting:ok'){
              that.setData({
                textcontent: '提示：您已经开启订阅消息'
              })
        }
        console.log(res.subscriptionsSetting)
        //返回subscriptionsSetting
        // res.subscriptionsSetting = {
        //   mainSwitch: true, // 订阅消息总开关
        //   itemSettings: {   // 每一项开关
        //     SYS_MSG_TYPE_INTERACTIVE: 'accept', // 小游戏系统订阅消息
        //     SYS_MSG_TYPE_RANK: 'accept',
        //     zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: 'reject', // 普通一次性订阅消息
        //     ke_OZC_66gZxALLcsuI7ilCJSP2OJ2vWo2ooUPpkWrw: 'ban',
        //   }
        // }
        //判断
        // if (res.subscriptionsSetting.mainSwitch) {
        //   if (res.subscriptionsSetting.itemSettings != null) {
        //     var sd = '953bKFK3Zfqh4Y9hURGt20Px5WzsfeiYg2xcZ_OkG7Q';
        //     // let item = res.subscriptionsSetting.itemSettings.P2wDrfX0CYmme5mgnmyxVdbXMZFp1mjByg9dE4_YrdQ
        //     let item = res.subscriptionsSetting.itemSettings.sd
        //     if (item == "reject") {
        //       that.setData({
        //         textcontent: '提示：您已经拒绝订阅消息'
        //       })
        //     } else if (item == "accept") {
        //       that.setData({
        //         textcontent: '提示：您已经开启订阅消息'
        //       })
        //     } else if (item == "ban") {
        //       that.setData({
        //         textcontent: '提示：您已经被后台封禁'
        //       })
        //     }
        //   }
        // } else {
        //   that.setData({
        //     textcontent: '提示：订阅消息未开启'
        //   })
        // }
      }
    })
  },

  //授权
  subTap: function () {
    const templateId = 'C6SPR6UBnynum3_z8CGejU0DVD32qqwcpeolyziYJg8'; // 订阅消息模版id
    let that = this;
    wx.requestSubscribeMessage({
      tmplIds: ['C6SPR6UBnynum3_z8CGejU0DVD32qqwcpeolyziYJg8'],
      success(res) {
        that.setData({
          textcontent: '提示：授权成功'
        })
      },
      fail(res) {
        that.setData({
          textcontent: '提示：授权失败'
        })
      }
    })


    // let that = this;
    // wx.requestSubscribeMessage({
    //   tmplIds: ['953bKFK3Zfqh4Y9hURGt20Px5WzsfeiYg2xcZ_OkG7Q'],
    //   success(res) {
    //     that.setData({
    //       textcontent: '提示：授权成功'
    //     })
    //   },
    //   fail(res) {
    //     that.setData({
    //       textcontent: '提示：授权失败'
    //     })
    //   }
    // })
  },
});